package com.jdkdongtaidaili;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.text.SimpleDateFormat;

public class StudentProxy {
    public static void main(String[] args) {
        StudentImpl studentImpl = new StudentImpl();
        Istudent student = (Istudent) Proxy.newProxyInstance(studentImpl.getClass().getClassLoader(), studentImpl.getClass().getInterfaces(), new InvocationHandler() {
            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                Object invoke = method.invoke(studentImpl, args);
                long l = System.currentTimeMillis();
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("YY-MM-dd HH:mm-ss");
                String format = simpleDateFormat.format(l);
                System.out.println("调用 " + method.getName() + "  在 " + format);
                return invoke;
            }
        });
        Student student1 = new Student("zhangsan",13);
        student.eat(student1);
        student.sleep(student1);
    }
}
